package com.spring.example2.listener;

import com.alibaba.fastjson.JSON;
import com.spring.example2.MqMessage;
import com.spring.example2.vo.TestPojo;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.springframework.stereotype.Component;

/**
 * author: chics
 * date: 2025/11/10
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "test-demo-send6",consumerGroup = "demo-test-consumer-group02")
public class Test2RocketmqListener extends BaseRocketmqListener<TestPojo> {

    @Override
    protected boolean handleMessage(MqMessage<TestPojo> body, MessageExt messageExt) {
        log.info("test2 recevied messgae = "+ JSON.toJSONString(body));
        TestPojo body1 = JSON.parseObject(JSON.toJSONString(body.getBody()), TestPojo.class);
        log.info("test2 recevied messgae = key = "+ body.getMessageKey());
        log.info("test2 recevied messgae = name = "+ body1.getName());
//        int i = 1/0;
        return true;
    }

    @Override
    protected int getMaxRetryCount() {
        return 2;
    }
}
